<?
	$sess = new Zend_Session_Namespace(CLU_NS);
?>
<div style="background-color:#ffffff">
<script type="text/javascript" src="/public/library/jquery/tablednd/jquery.tablednd_0_5.js"></script>
<!--<form accept-charset="UTF-8" action="/</?=$sess->viewLang?>/admin/ajax/update-multiple-weights" method="GET">-->
	<table id="table" cellspacing="0" cellpadding="2" border="2" style="width:auto;height:80px;">
		<? $id = 1; ?>
		<?foreach ($this->viewParams['weights'] as $w ) :?>
		    <tr id="<?=$w['content_id']?>">
		    	<td style="text-align:center;width:20px;"><?=$w['weight']?></td>
		    	<td style="text-align:center;width:40px;"><?=$w['content_id']?></td>
		    	<?if(isset($w['name'])) :?>
		    	<td width="190px;"><?=$w['name']?></td>
		    	<?endif?>
		    	<?if(isset($w['title'])) :?>
		    	<td width="190px;"><?=$w['title']?></td>
		    	<?endif?>
		    	<td><?=$w['widget_position_id']?></td>
		    </tr>
		<? $id ++ ?>    
		<?endforeach?>
	</table>
	<input type="submit" class="submit_value" value="Save Order" />
	<input type="hidden" class="order" name="order" value=""/>
	
<!--</form>-->
<script type="text/javascript">
$(document).ready(function() {
    // Initialise the table
 	$('#table').tableDnD({
        onDrop: function(table, row) {
        var rows = table.rows;
        tmp = '';
        for (var i=0; i<rows.length; i++) {
            var rowId = rows[i].id;
            tmp = tmp + rowId + ",";
        }
        $('.order').attr('value', tmp);
      }
    });
    
    $("input.submit_value").click(function()
		{   
			$.getJSON("/<?=$sess->viewLang?>/admin/ajax/update-multiple-weights",
				{
					order: $('.order').attr('value'),
				}, 
                function(json){
                	console.log(json);
                    if(json.success)
                    {
                    	alert('Success');
                    }
                    else
                    	alert('fail');
             })
     });
});
</script>
</div>